package xyz.zhzby.cyzx.cms.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.zhzby.cyzx.cms.dto.response.ChannelResponse;
import xyz.zhzby.cyzx.cms.entity.Channel;
import xyz.zhzby.cyzx.cms.service.IChannelService;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;

import java.util.List;

/**
 * @author zby
 * @date 2021/12/11
 */
@RestController
@RequestMapping("/cms/channel")
@ApiModel("文章分栏相关API")
public class ChannelController {

    @Autowired
    private IChannelService channelService;

    @ApiOperation("创建分栏")
    @PostMapping("")
    public RestResponse<String> createChannel(@RequestBody Channel channel) {
        channelService.createChannel(channel);
        return RestResponse.success("创建成功");
    }

    @ApiOperation("修改分栏信息")
    @PutMapping("")
    public RestResponse<String> updateChannel(@RequestBody Channel channel) {
        return channelService.updateChannel(channel);
    }

    @ApiOperation("根据ID获取分栏")
    @GetMapping("/{channelID}")
    public RestResponse<ChannelResponse> getChannel(@PathVariable("channelID") Long channelID) {
        return RestResponse.success(channelService.getChannelById(channelID));
    }

    @ApiOperation("查看当前用户的所有分栏（不用分页）")
    @GetMapping("/list")
    public RestResponse<List<ChannelResponse>> getAllChannels() {
        return channelService.getAllChannels();
    }

    @ApiOperation("删除分栏")
    @DeleteMapping("/{channelID}")
    public RestResponse<String> deleteChannel(@PathVariable("channelID") Long channelID) {
        return channelService.deleteChannel(channelID);
    }

}
